package v1

import (
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"gin-vue-admin/utils"
	"strconv"
	"time"

	"github.com/gin-gonic/gin"
)

// Get{{.StructName}}List
// @Tags Sys{{.StructName}}
// @Summary 查询{{.Label}}列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.Query{{.StructName}} true " "
// @success 200 {object} response.Response{data=[]model.Sys{{.StructName}}} "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /{{.Abbreviation}}/get{{.StructName}}List [get]
func Get{{.StructName}}List(c *gin.Context) {
	var pageInfo request.Query{{.StructName}}
	_ = c.ShouldBindQuery(&pageInfo)
	if err := utils.Verify(pageInfo); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := service.Get{{.StructName}}InfoList(pageInfo)
	pagination := response.Pagination{PageNum: pageInfo.PageNum, PageSize: pageInfo.PageSize, Total: total}
	response.RespondList(list, pagination, err, c)
}

// Create{{.StructName}}
// @Tags Sys{{.StructName}}
// @Summary 新增{{.Label}}
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Sys{{.StructName}} true " "
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /{{.Abbreviation}}/add{{.StructName}} [post]
func Create{{.StructName}}(c *gin.Context) {
	var {{.Abbreviation}} model.Sys{{.StructName}}
	_ = c.ShouldBindJSON(&{{.Abbreviation}})
	if err := utils.Verify({{.Abbreviation}}); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	err := service.Create{{.StructName}}({{.Abbreviation}})
	response.RespondOperate(err, c)
}

// Update{{.StructName}}
// @Tags Sys{{.StructName}}
// @Summary 更新{{.Label}}
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.Sys{{.StructName}} true " "
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /{{.Abbreviation}}/update{{.StructName}} [put]
func Update{{.StructName}}(c *gin.Context) {
	var {{.Abbreviation}} model.Sys{{.StructName}}
	_ = c.ShouldBindJSON(&{{.Abbreviation}})
	if err := utils.Verify({{.Abbreviation}}); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	err := service.Update{{.StructName}}({{.Abbreviation}})
	response.RespondOperate(err, c)
}

// Query{{.StructName}}
// @Tags Sys{{.StructName}}
// @Summary 查询{{.Label}}信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param id path int true " "
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /{{.Abbreviation}}/{id} [get]
func Query{{.StructName}}(c *gin.Context) {
	{{.Abbreviation}}Id, _ := strconv.Atoi(c.Param("id"))
	if {{.Abbreviation}}Id == 0 {
		response.FailWithMessage("id不能为空", c)
	}

	{{.Abbreviation}}, err := service.Query{{.StructName}}(uint64({{.Abbreviation}}Id))
	response.RespondData({{.Abbreviation}}, err, c)
}

// Delete{{.StructName}}
// @Tags Sys{{.StructName}}
// @Summary 批量删除{{.Label}}
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true " "
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /{{.Abbreviation}}/delete{{.StructName}} [delete]
func Delete{{.StructName}}(c *gin.Context) {
	var reqIds request.IdsReq
	_ = c.ShouldBindJSON(&reqIds)
	if err := utils.Verify(reqIds); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	err := service.Delete{{.StructName}}(reqIds.Ids)
	response.RespondOperate(err, c)
}
